$.ajax({
    type:"post",
    url:"/system/toPositionList",
    data:{},
    dataType:"json",
    success:function(r){
        if (r.data != null){
            var t="<tr>" +
                "         <th>序号</th>" +
                "         <th>职位</th>" +
                "         <th>所属部门</th>" +
                "         <th>状态</th>" +
                "         <th>操作</th>" +
                "       </tr>";
            for (var i=0;i < r.data.length;i++){
                var n=""
                var m=""
                var k=""
                if (r.data[i].job_state==0){
                    n="正常"
                    m="撤销"
                    k="是否确认撤销此条信息？"
                }else {
                    n="已撤销"
                    m="恢复"
                    k="是否确认恢复此条信息？"
                }
                t += "<tr> <td>"+r.data[i].job_id+"</td><td>"+r.data[i].job_name+"</td><td>"+r.data[i].dept.dept_name+"</td><td>"+n+"</td><td>\n" +
                    "         <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                    "         <a href=\"javascript:void(0)\" class=\"tablelink\">赋权</a>\n" +
                    "         <a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen('"+k+"')\">"+m+"</a>\n" +
                    "       </td></tr>"
            }
            $(".tablelist").html(t)
            var pagenum = document.getElementById("pagenum");
            pagenum.innerHTML=r.pageNum
            var totalrows = document.getElementById("totalrows");
            totalrows.innerHTML=r.totalRows

            $(".tablelink").click(function(){

                var text = $(this).text();
                var job_id = $(this).parents("tr")[0].children[0].innerHTML
                if (text=="修改"){
                    window.location.href="/system/updatePositionView/"+ job_id
                }else if(text=="赋权"){
                    window.location.href="/system/fuquanID/"+ job_id
                }else if(text=="恢复"){
                    $("#sure").click(function () {
                        $.ajax({
                            type: "post",
                            url: "/system/updateJobPositionByState/"+ job_id+"/"+0,
                            data: {},
                            dataType: "json",
                            success: function (r) {
                                if (r=="true"){
                                    alert("修改成功")
                                    location.reload();
                                }else{
                                    alert("修改失败")
                                }
                            }
                        })
                    })
                }else if(text=="撤销"){
                    $("#sure").click(function () {
                        $.ajax({
                            type: "post",
                            url: "/system/updateJobPositionByState/"+ job_id+"/"+1,
                            data: {},
                            dataType: "json",
                            success: function (r) {
                                if (r=="true"){
                                    alert("修改成功")
                                    location.reload();
                                }else{
                                    alert("修改失败")
                                }
                            }
                        })
                    })
                }
            });



            $("#shangyiye").click(function () {
                if (pagenum.innerHTML>1){
                    pagenum.innerHTML=Number(pagenum.innerHTML)-1;
                }else{
                    alert("已经是第一页了")
                }

                var n=pagenum.innerHTML
                if (n>=1){
                    $.ajax({
                        type:"post",
                        url:"/system/toPositionList",
                        data:{pageNum:n},
                        dataType:"json",
                        success:function(r){
                            if (r.data != null){
                                var t="<tr>" +
                                    "         <th>序号</th>" +
                                    "         <th>职位</th>" +
                                    "         <th>所属部门</th>" +
                                    "         <th>状态</th>" +
                                    "         <th>操作</th>" +
                                    "       </tr>";
                                for (var i=0;i < r.data.length;i++){
                                    var n=""
                                    var m=""
                                    var k=""
                                    if (r.data[i].job_state==0){
                                        n="正常"
                                        m="撤销"
                                        k="是否确认撤销此条信息？"
                                    }else {
                                        n="已撤销"
                                        m="恢复"
                                        k="是否确认恢复此条信息？"
                                    }
                                    t += "<tr> <td>"+r.data[i].job_id+"</td><td>"+r.data[i].job_name+"</td><td>"+r.data[i].dept.dept_name+"</td><td>"+n+"</td><td>\n" +
                                        "         <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                                        "         <a href=\"javascript:void(0)\" class=\"tablelink\">赋权</a>\n" +
                                        "         <a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen('"+k+"')\">"+m+"</a>\n" +
                                        "       </td></tr>"
                                }
                                $(".tablelist").html(t)
                                $(".tablelink").click(function(){

                                    var text = $(this).text();
                                    var job_id = $(this).parents("tr")[0].children[0].innerHTML
                                    if (text=="修改"){
                                        window.location.href="/system/updatePositionView/"+ job_id
                                    }else if(text=="赋权"){
                                        window.location.href="/system/fuquanID/"+ job_id
                                    }else if(text=="恢复"){
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateJobPositionByState/"+ job_id+"/"+0,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                }
                                            })
                                        })
                                    }else if(text=="撤销"){
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateJobPositionByState/"+ job_id+"/"+1,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                }
                                            })
                                        })
                                    }
                                });
                            }
                        },
                        error:function (r) {
                            alert("!!!")
                        }

                    })
                }else{
                    alert("已经是第一页了")
                }


            })


            $("#xiayiye").click(function () {
                if (pagenum.innerHTML<r.totalPage){
                    pagenum.innerHTML=Number(pagenum.innerHTML)+1
                }else{
                    alert("已经是最后一页了")
                }

                var n=pagenum.innerHTML
                if (n<=r.totalPage){
                    $.ajax({
                        type:"post",
                        url:"/system/toPositionList",
                        data:{pageNum:n},
                        dataType:"json",
                        success:function(r){
                            if (r.data != null){
                                var t="<tr>" +
                                    "         <th>序号</th>" +
                                    "         <th>职位</th>" +
                                    "         <th>所属部门</th>" +
                                    "         <th>状态</th>" +
                                    "         <th>操作</th>" +
                                    "       </tr>";
                                for (var i=0;i < r.data.length;i++){
                                    var n=""
                                    var m=""
                                    var k=""
                                    if (r.data[i].job_state==0){
                                        n="正常"
                                        m="撤销"
                                        k="是否确认撤销此条信息？"
                                    }else {
                                        n="已撤销"
                                        m="恢复"
                                        k="是否确认恢复此条信息？"
                                    }
                                    t += "<tr> <td>"+r.data[i].job_id+"</td><td>"+r.data[i].job_name+"</td><td>"+r.data[i].dept.dept_name+"</td><td>"+n+"</td><td>\n" +
                                        "         <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                                        "         <a href=\"javascript:void(0)\" class=\"tablelink\">赋权</a>\n" +
                                        "         <a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen('"+k+"')\">"+m+"</a>\n" +
                                        "       </td></tr>"
                                }
                                $(".tablelist").html(t)
                                $(".tablelink").click(function(){

                                    var text = $(this).text();
                                    var job_id = $(this).parents("tr")[0].children[0].innerHTML
                                    if (text=="修改"){
                                        window.location.href="/system/updatePositionView/"+ job_id
                                    }else if(text=="赋权"){
                                        window.location.href="/system/fuquanID/"+ job_id
                                    }else if(text=="恢复"){
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateJobPositionByState/"+ job_id+"/"+0,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                }
                                            })
                                        })
                                    }else if(text=="撤销"){
                                        $("#sure").click(function () {
                                            $.ajax({
                                                type: "post",
                                                url: "/system/updateJobPositionByState/"+ job_id+"/"+1,
                                                data: {},
                                                dataType: "json",
                                                success: function (r) {
                                                }
                                            })
                                        })
                                    }
                                });
                            }
                        },
                        error:function (r) {
                            alert("!!!")
                        }

                    })
                }else{
                    alert("已经是最后一页了")
                }


            })


        }
    },
    error:function (r) {
        alert("!!!")
    }

})


$("#check").click(function () {

var name=$("#jobName").val()

var options=$("#deptName option:selected")
var deptname=options.text()
var jdid;
if (deptname=="市场部"){
    jdid="1"
}else if(deptname=="采购部"){
    jdid="2"
}else if(deptname=="财务部"){
    jdid="3"
}else if(deptname=="行政部"){
    jdid="4"
}else if(deptname=="董事会"){
    jdid="5"
}else if(deptname=="特殊部门"){
    jdid="6"
}

$.ajax({
    type: "post",
    url: "/system/queryOneJob",
    data: {job_name: name,job_dept_id:jdid},
    dataType: "json",
    success: function (r) {
        if (r!=null){
            var t="<tr>" +
                "         <th>序号</th>" +
                "         <th>职位</th>" +
                "         <th>所属部门</th>" +
                "         <th>状态</th>" +
                "         <th>操作</th>" +
                "       </tr>";
            var n=""
            var m=""
            var k=""
            if (r[0].job_state==0){
                n="正常"
                m="撤销"
                k="是否确认撤销此条信息？"
            }else {
                n="已撤销"
                m="恢复"
                k="是否确认恢复此条信息？"
            }
            t += "<tr> <td>"+r[0].job_id+"</td><td>"+r[0].job_name+"</td><td>"+r[0].dept.dept_name+"</td><td>"+n+"</td><td>\n" +
                "         <a href=\"javascript:void(0)\" class=\"tablelink\">修改</a>\n" +
                "         <a href=\"javascript:void(0)\" class=\"tablelink\">赋权</a>\n" +
                "         <a href=\"javascript:void(0)\" class=\"tablelink\" onclick=\"tipOpen('"+k+"')\">"+m+"</a>\n" +
                "       </td></tr>"
            $(".tablelist").html(t)
            $(".tablelink").click(function(){

                var text = $(this).text();
                var job_id = $(this).parents("tr")[0].children[0].innerHTML
                if (text=="修改"){
                    window.location.href="/system/updatePositionView/"+ job_id
                }else if(text=="赋权"){
                    window.location.href="/system/fuquanID/"+ job_id
                }else if(text=="恢复"){
                    $("#sure").click(function () {
                        $.ajax({
                            type: "post",
                            url: "/system/updateJobPositionByState/"+ job_id+"/"+0,
                            data: {},
                            dataType: "json",
                            success: function (r) {
                            }
                        })
                    })
                }else if(text=="撤销"){
                    $("#sure").click(function () {
                        $.ajax({
                            type: "post",
                            url: "/system/updateJobPositionByState/"+ job_id+"/"+1,
                            data: {},
                            dataType: "json",
                            success: function (r) {
                            }
                        })
                    })
                }
            });
        }
    }
})

})


